package com.util;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

//import com.opensymphony.xwork2.ActionSupport;

public class Config {
	/**
	 * 
	 */
	public static String userName;
	public static String password;
	public static String databaseName;
	public static String databasePath;
	public static String databaseType;
	
	public static String driverName;
	public static String urlPattern;
	public static int portNumber;
	
	public Config(){
		
		setDriverName("com.mysql.jdbc.Driver");
		setUrlPattern("jdbc:mysql:");
		
		try{
		Document document = XmlUtil.getDocument();
		NodeList list = document.getElementsByTagName("config");
		if (list.getLength() != 0) {
			for (int x = 0; x < list.getLength(); x++) {
				Element config_tag = (Element) list.item(x);
				
				String s = config_tag.getElementsByTagName("databaseType").item(0).getTextContent();
				this.setDatabaseType(config_tag.getElementsByTagName("databaseType").item(0).getTextContent());
				this.setDatabasePath(config_tag.getElementsByTagName("databasePath").item(0).getTextContent());
				this.setPortNumber(Integer.parseInt(config_tag.getElementsByTagName("portNumber").item(0).getTextContent()));
				
				this.setDatabaseName(config_tag.getElementsByTagName("databaseName").item(0).getTextContent());
				this.setUserName(config_tag.getElementsByTagName("userName").item(0).getTextContent());
				this.setPassword(config_tag.getElementsByTagName("password").item(0).getTextContent());
				
				//this.setDatabaseType(config_tag.getElementsByTagName("databaseType").item(0).getTextContent());
				//this.setDatabaseType(config_tag.getElementsByTagName("databaseType").item(0).getTextContent());
			}
		}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	public static int getPortNumber() {
		return portNumber;
	}
	public static void setPortNumber(int portNumber) {
		Config.portNumber = portNumber;
	}
	public static String getDatabaseType() {
		return databaseType;
	}
	public static String getDriverName() {
		return driverName;
	}
	public static void setDriverName(String driverName) {
		Config.driverName = driverName;
	}
	public static String getUrlPattern() {
		return urlPattern;
	}
	public static void setUrlPattern(String urlPattern) {
		Config.urlPattern = urlPattern;
	}
	public static void setDatabaseType(String databaseType) {
		Config.databaseType = databaseType;
	}
	public static String getUserName() {
		return userName;
	}
	public static void setUserName(String userName) {
		Config.userName = userName;
	}
	public static String getPassword() {
		return password;
	}
	public static void setPassword(String password) {
		Config.password = password;
	}
	public static String getDatabaseName() {
		return databaseName;
	}
	public static void setDatabaseName(String databaseName) {
		Config.databaseName = databaseName;
	}
	public static String getDatabasePath() {
		return databasePath;
	}
	public static void setDatabasePath(String databasePath) {
		Config.databasePath = databasePath;
	}
}
